<template>
  <div class="scroll-container" ref="scrollContainer" @wheel.prevent="handleScroll" >
    <!-- 网站LOGO -->
    <div class="sidebar-logo">
      <router-link :to="{name:'Dashboard'}">
        <div v-if="$store.getters.sidebar.opened" class="logo-text">{{$t('webTitle')}}</div>
        <!-- <div v-else class="logo-colse">后台</div> -->
        <div v-else class="logo-colse">
          <el-tooltip effect="dark" :content="$t('webTitle')" placement="right">
            <svg-icon icon-class="crm" />
          </el-tooltip>
        </div>
      </router-link>
    </div>
    <div class="scroll-wrapper" ref="scrollWrapper" :style="{top: top+50 + 'px'}">
      <slot></slot>
    </div>
  </div>
</template>

<script>
const delta = 15

export default {
  name: 'scrollBar',
  data() {
    return {
      top: 0
    }
  },
  methods: {
    handleScroll(e) {
      const eventDelta = e.wheelDelta || -e.deltaY * 3
      const $container = this.$refs.scrollContainer
      const $containerHeight = $container.offsetHeight
      const $wrapper = this.$refs.scrollWrapper
      const $wrapperHeight = $wrapper.offsetHeight
      if (eventDelta > 0) {
        this.top = Math.min(0, this.top + eventDelta)
      } else {
        if ($containerHeight - delta < $wrapperHeight) {
          if (this.top < -($wrapperHeight - $containerHeight + delta)) {
            this.top = this.top
          } else {
            this.top = Math.max(this.top + eventDelta, $containerHeight - $wrapperHeight - delta)
          }
        } else {
          this.top = 0
        }
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import '../../styles/variables.scss';
$logoIconHeight: 50px;

.scroll-container {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: $menuBg;
  .scroll-wrapper {
    position: absolute;
     width: 100%!important;
  }
}

.sidebar-logo{
  height: $logoIconHeight;
  line-height: $logoIconHeight;
  text-align: center;
  border-bottom: 1px solid lighten($menuBg, 6%);
  .logo-colse,
  .logo-text{
    color: #FFF;
  }

  .logo-colse{
    font-size: 12px;
    font-weight: bold;
    height: $logoIconHeight;
    .svg-icon{
      margin: 0!important;
      font-size: 26px;
      height: $logoIconHeight;
      text-align: center;
    }
  }
}
</style>
